
package com.idm.tacacs.utils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class TacascsUtil {

	public static Connection openConnection() throws Exception{
		Connection objConnection = null;
		String strMethodName = null;
		String strDataSource = null;
		try{
			strMethodName="openConnection";
			objConnection = MSSQLDAOFactory.createConnection();
		}catch(Exception objException){
			System.out.println("Error : " + objException);
			throw new Exception("DB_GENERIC_ERROR");
		}finally{
			strMethodName = null;
			strDataSource = null;
		}
		return objConnection;
	}

	public static boolean closeConnection(Connection objConnection,Statement objCallableStatement,ResultSet objResultSet) throws Exception{
		boolean bError = false;
		String strMethodName = "closeConnection";
		try{
			if(objResultSet!=null){
				objResultSet.close();
				objResultSet = null;
			}
		}catch(Exception objException){
			bError = true;
		}
		try{
			if(objCallableStatement!=null){
				objCallableStatement.close();
				objCallableStatement = null;
			}
		}catch(Exception objException){
			bError = true;
		}		
		try{
			if(objConnection!=null){
				objConnection.close();
				objConnection = null;
			}
		}catch(Exception objException){
			bError = true;
		}
		if(bError == true){
			throw new TacacsException("DB_GENERIC_ERROR");
		}
		return bError;
	}


}
